package priv.pattern.responsibility.service.impl;

import priv.pattern.responsibility.pojo.ResponsibilityEnum;
import priv.pattern.responsibility.service.Handler;

import java.util.Arrays;

/*
 * 作者：m鹏h
 * 时间；2024/5/31 23:16
 * 描述：经理的职责
 **/
public class ManagerImpl extends Handler {
    //职责
    Integer[] myResponsibility = {ResponsibilityEnum.APPLY_FOR_A_JOB.getCode(), ResponsibilityEnum.BUY_OFFICE_APPLIANCES.getCode()};

    @Override
    public String isResponsble(Integer code) {
        if (Arrays.asList(myResponsibility).contains(code)) {
            //switch中不可以用变量，所以根据code 获取枚举类
            ResponsibilityEnum typeByCode = ResponsibilityEnum.findTypeByCode(code);
            if (typeByCode != null) {
                switch (typeByCode) {
                    case APPLY_FOR_A_JOB:
                        System.out.println("我是经理，我批准你去招人");
                        break;
                    case BUY_OFFICE_APPLIANCES:
                        System.out.println("我是经理，我批准你去购买办公电器");
                        break;
                    default:
                        throw new IllegalStateException("经理 Unexpected value: " + code);
                }
            }

        } else {
            if (code < ResponsibilityEnum.BUY_OFFICE_APPLIANCES.getCode()) {
                System.out.println("我是经理，这些审批不归我管");
            } else {
                System.out.println("我是经理，这些审批我的职位还不够！！！");
                handler.isResponsble(code);
            }
        }
        return null;
    }
}
